<div id="new-event-dlg" style="font-size: 62.5%; display: none;" title="Nowa rezerwacja">
	<form id="new-event-form" method="post" action="<?php echo Yii::app()->request->baseUrl; ?>/index.php/calendar/editStudentReservation">
		<p class="validateTips"></p>
		<input type="hidden" name="id" class="id" >
		<input id="eventname" class="eventname" name="name" disabled="disabled">
		<label for="stationname">Stanowisko: </label>
		<input id="stationname" class="stationname" name="stationname" disabled="disabled">
		<label for="startdate">Początek zajęć: </label>
		<input disabled="disabled" class="startdate" id="startdate" name="startdate">
		<label for="enddate" id="enddate">Koniec zajęć: </label>
		<input disabled="disabled" class="enddate" name="enddate">
		
		<label for="occupied">Zapisanych: </label>
		<input id="occupied" class="occupied" name="occupied" disabled="disabled">
		<label for="limit">Limit: </label>
		<input id="limit" class="limit" name="limit" disabled="disabled"><br>
	</form>
</div>

<script>

function readStations(data) {
	var reserv = data.reserv;
	
	$("#new-event-station").html('');
	
	if(reserv.length!=0)
	{
		$("input[name='name']").val('Zapisany!');
	}
	else
	{
		$("input[name='name']").val('Nie zapisany');
	}
}


function updateEditTips( t ) {
	var tips = $("#new-event-dlg .validateTips");
	tips.text( t ).addClass( "ui-state-highlight" );
	setTimeout(function() {
		tips.removeClass( "ui-state-highlight", 1500 );
	}, 500 );
};

function validateLimitStudent() {
	if ( $("#new-event-dlg .limit").val() == $("#new-event-dlg .occupied").val()) {
		updateEditTips('Nie możesz się zapisać. Brak miejsc!');
		return false;
	}
	else{
		return true;
	}
}

$(function() {
	
	$( "#new-event-dlg" ).dialog({
		autoOpen: false,
		height: 510,
		width: 350,
		modal: true,
		resizable: false,
		buttons : {
			"Zapisz":function(){
				if ( validateLimitStudent() ) {
					$.post(
							'<?php echo Yii::app()->request->baseUrl; ?>/index.php/calendar/addStudentReservation',
							$("#new-event-form").serialize(),
							function(data) {
								$('#calendar').fullCalendar( 'refetchEvents' );
							},
							"json"
						);
						$( this ).dialog( "close" );
				}
			},
			"Anuluj": function() {
				$( this ).dialog( "close" );
			}
		},
		open: function() {
			$("#new-event-dlg .validateTips").html('');
		}
	});
});
</script>